/**
 * author:Administrator
 * date:2016/1/4
 * desc:TODO
 */

'use strict';

var Router = require('koa-router');
var bodyParser = require('koa-better-body');

var __pathPrefix = '/orders';
var router = new Router({prefix: __pathPrefix});
module.exports = router.routes();

var biz = require('../biz/order.js');

router.get('/reset', function*() {
  var retobj = yield biz.reset();
  retobj = yield biz.newOrder();
  //console.log({errcode: 0, order: retobj._doc});
  this.body = {errcode: 0, order: retobj._doc};
});

router.post('/payment', function*() {
  var oid = this.request.inParams.fields.orderid;
  var retobj = yield biz.payment(oid);
  if (retobj) {
    this.body = {errcode: 0}
  } else {
    console.log('该订单不存在 或 不处于可支付状态');
    this.body = {errcode: 1, msg: '该订单不存在 或 不处于可支付状态'}
  }
});